var emailflag = false;

function login() {
	var dialog = art.dialog({id: 'login',title: false,lock:true,padding:0});

	// jQuery ajax   
	$.ajax({
	    url: '/login',
	    success: function (data) {
	        dialog.content(data);
	    },
	    cache: false
	});
}

function getPassword() {
	art.dialog.open('/login/getPassword', {
		id : 'getPassword',
		lock : true,
		esc : false,
		fixed : true,
		resize : false,
		drag : false,
		zIndex : 9999
	});
}

function actregwin(){
	art.dialog.open('/reg/actregwin', {
		id : 'actregwin',
		width : 460,
		height : 460,
		lock : true,
		esc : false,
		fixed : true,
		resize : false,
		drag : false,
		zIndex : 9999
	});
}

function exit() {
	art.dialog.confirm("确认要退出吗？", function() {
		$.ajax({
			type : 'POST',
			url : '/login/out',
			dataType : 'json',
			success : function(r) {
				if (r.status == 1) {
					window.location.reload();
				}
			}
		});
	});
}

function openreg() {
	window.open('/register');
	art.dialog.close();
}

function counttotal() {
	var e = $('#top_reg_e').attr('value');
	var z = $('#top_reg_z').attr('value');
	var v = e != '' && z != '' ? parseInt(e) + parseInt(z) : '';
    $('#top_reg_t').attr('value', v);
}

function IsMail(mail) {
	var patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if (!patrn.test(mail)){
		return false;
	}else{
		return true;
	}
}

function IsMobile(mobile) {
	var patrn = /^[0-9]{11}$/;
	if (!patrn.test(mobile)){
		return false;
	}else{
		return true;
	}
}

function CheckEmail_top() {
	var Val = $('#top_reg_email').val();
	var projectid = $('#projectid').attr('value');
	var schoolids = $("#schoolid").val();
	if (IsMail(Val)) {
		$.ajax({
			async : false,
			type : "POST",
			url : "/reg/verfiyemail",
			data : "email=" + Val + "&projectid=" + projectid,
			success : function(msg) {
				if (1 == msg) {
					$('#top_emailtip').html("<span style='color:#d55437;'>该用户已存在！</span>");
					$('#top_reg_email').focus();
				} else {
					$('#top_emailtip').html("<img src='/resource/2013/home/images/ico/ok.png' />  正确");
					emailflag = true;
				}
			}
		});
	} else {
		$('#top_emailtip').html("<img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'> 邮箱不正确！</span>");
		$('#top_reg_email').focus();
	}
}

function vPassword(){
    var Val1 = $('#top_reg_pwd').attr('value');
    var Val2 = $('#re_top_reg_pwd').attr('value');
    
    if(Val1==''){
        $('#top_pwdtip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'>密码不能为空！</span>");
        $('#top_reg_pwd').focus();
    } else {
      if(Val1.length<=3){
        $('#top_repwdtip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'>密码不能少于3个字符！</span>");
        $('#re_top_reg_pwd').focus();
      } else {
        if(Val1 != Val2){
            $('#top_repwdtip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'>两次密码不一致！</span>");
            $('#top_pwdtip').focus();
        } else {
            $('#top_pwdtip').html(" <img src='/resource/2013/home/images/ico/ok.png' /> 正确");
            $('#top_repwdtip').html(" <img src='/resource/2013/home/images/ico/ok.png' /> 正确");
			passwordflag = true;
        }       
      }
    }
}

function vRealName(){
    var Val = $('#top_reg_nickname').attr('value');
    
    if(Val==''){
        $('#top_nicknametip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'>真实姓名不能为空!</span>");
        $('#top_reg_nickname').focus();
    } else {
      if(Val.length<2){
        $('#top_nicknametip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'>真实姓名不能少于2个字符!</span>");
        $('#top_reg_nickname').focus();
      } else {
         $('#top_nicknametip').html("<img src='/resource/2013/home/images/ico/ok.png' /> 正确");
		nikenameflag = true;
      }
    }
}

function vTel(){
	  var Val = $('#top_reg_mobile').attr('value');
	    
	  if(IsMobile(Val)){
	    if(Val==''){
	        $('#top_mobiletip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'> 手机号码不能为空！</span>");
			$('#top_reg_mobile').focus();
	    } else {
	         $('#top_mobiletip').html("<img src='/resource/2013/home/images/ico/ok.png' /> 正确");
			mobileflag = true;
	    }
	  } else {
	      $('#top_mobiletip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'> 手机不正确！</span>");
	      $('#top_reg_mobile').focus();
	  }  
	}

function vTotal(){
	  var english = $('#top_reg_e').attr('value');
	  var zonghe = $('#top_reg_z').attr('value');
	  
	    
	    if(english =='' || zonghe==''){
	        $('#top_cjtip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'> 请填写考试成绩！</span>");
	        $('#top_reg_e').focus();
	    } else {
	        var engnum = parseInt(english);
	        var zonnum = parseInt(zonghe);
	        
	        if(engnum<10 || engnum>100 || zonnum < 10 || zonnum > 200) {
	           $('#top_cjtip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'> 请填写考试成绩！</span>"); 
	           $('#top_reg_e').focus();
	        } else {
	         $('#top_cjtip').html("<img src='/resource/2013/home/images/ico/ok.png' /> 正确");
	            totalflag = true;
	        }
	    }
	}

	function vFirstwish(){
	  var Val = $('#top_reg_school').attr('value');
	    if(Val==''){
	        $('#top_schooltip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'> 请选择考试所在院校！</span>");
			$('#top_reg_school').focus();
	    } else {
	         $('#top_schooltip').html("<img src='/resource/2013/home/images/ico/ok.png' /> 正确");
			firstwishflag = true;
	    }
	}

	function vTestno(){
	  var Val = $('#top_reg_testno').attr('value');
	    
	    if(Val==''){
	        $('#top_testnotip').html(" <img src='/resource/2013/home/images/ico/erorr.png' /><span style='color:#d55437;'> 请填写准考证！</span>");
			$('#top_reg_testno').focus();
	    } else {
	         $('#top_testnotip').html("<img src='/resource/2013/home/images/ico/ok.png' /> 正确");
			testnoflag = true;
	    }
	}

function registerTop(){
	emailflag = false;
	passwordflag = false;
	nikenameflag = false;
	mobileflag = false;
	totalflag = false;
	firstwishflag = false;
	testnoflag = false;

	CheckEmail_top();
	if(!emailflag){
		return false;
	}
	
	vPassword();
	if(!passwordflag){
		return false;
	}
	
	vRealName();
	if(!nikenameflag){
		return false;
	}
	
	vTel();
	if(!mobileflag){
		return false;
	}
	
	vTotal();
	if(!totalflag){
		return false;
	}
	
	vFirstwish();
	if(!firstwishflag){
		return false;
	}
	
	vTestno();
	if(!testnoflag){
		return false;
	}
	
	var email = $("#top_reg_email").val();
	var pwd = $("#top_reg_pwd").val();
	var nickname = $("#top_reg_nickname").val();
	var mobile = $("#top_reg_mobile").val();
	var degree = $("#top_reg_degree").val();
	var e = $("#top_reg_e").val();
	var z = $("#top_reg_z").val();
	var t = $("#top_reg_t").val();
	var school = $("#top_reg_school").val();
	var testno = $("#top_reg_testno").val();
	var schoolid = $("#schoolid").val();
	var sarea = $("#sarea").val();
	
	$.ajax({
		type:'POST',
		url:'/reg/topReg',
		 beforeSend:function(){
			   art.dialog({
					id:'regtips',
					content:'<img src="/resource/js/ajaxloading.gif"> 请稍候...',
					lock : true,
					esc : false,
					fixed : true,
					resize : false,
					drag : false,
					cancel : false
			   });
		   },
		data:{email:email,password:pwd,realname:nickname,tel:mobile,degree:degree,e:e,z:z,t:t,school:school,testno:testno,schoolid:schoolid,area:sarea},
		dataType:'json',
		success:function(r){
			if(r.status == 1){
				$(".topzc").slideToggle(300);
				art.dialog.data('a',{a:r.data.usinfo,b:r.data.otherschool,u:r.data.u});
				var topregwin = art.dialog.open(r.data.url, {
					id : 'regtop',
					lock : true,
					esc : false,
					fixed : true,
					resize : false,
					drag : false,
					zIndex : 10010,
					close : function() {
						window.location.reload();
					}
				},false);
			}else{
				
			}
		}
	});
}

function regoneschool(tsid,area){
	$.ajax({
		type:'POST',
		url:'/reg/doRegoneschool',
		beforeSend:function(){
			   art.dialog({
					id:'regtips',
					content:'<img src="/resource/js/ajaxloading.gif"> 请稍候...',
					lock : true,
					esc : false,
					fixed : true,
					resize : false,
					drag : false,
					cancel : false
			   });
		   },
		data:{tsid:tsid,area:area},
		dataType:'json',
		success:function(r){
			if(r.status == 1){
				$(".topzc").slideToggle(300);
				art.dialog.data('a',{a:r.data.usinfo,b:r.data.otherschool,u:r.data.u,is:r.data.isschool});
				var topregwin = art.dialog.open(r.data.url, {
					id : 'regtop',
					lock : true,
					esc : false,
					fixed : true,
					resize : false,
					drag : false,
					zIndex : 10010,
					close : function() {
						window.location.reload();
					}
				},false);
			}else{
				art.dialog({id:'regtips'}).close();
				actregwin();
			}
		}
	});
}

function mianshifd(){
	art.dialog({
		id:'mianshifd',
		content:'<img src="/resource/new/images/2013/mstc.png" width="602" height="285">',
		padding:0,
		drag:false,
		resize:false,
		fixed:true,
		lock:true,
		opacity:0.2,
		okVal:'参加指导',
		ok:function(){
			$.ajax({type:'POST',url:'/reg/doMianshifd',dataType:'json',success:function(msg){ 
				if(msg.status == 1){
					art.dialog.alert('非常感谢您的参加，MBA全国面试服务中心工作人员会尽快与您联系。');
					art.dialog({id:'mianshifd'}).close();
				}else{
					art.dialog.tips('不能重复参加');
				}
			}});
		},
		cancel : true
	});
}

